package Wust_Java_Club_Middle_Test;

import java.util.Scanner;

public class Knapsack_Problem {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int v = in.nextInt();
		int n =in.nextInt();
		int[] weight = new int[n+1];
		//dp[i][j]代表前i个物品有j体积的背包，目前能使用的最大体积
		int[][]dp = new int[2][v+1];
		for(int i =1;i<=n;i++) {
			weight[i]=in.nextInt();
		}
		for(int i=1;i<=n;i++) {
			for(int j=0;j<=v;j++) {
				if(j>=weight[i]) {
					dp[i&1][j]=Math.max(dp[(i-1)&1][j], dp[(i-1)&1][j-weight[i]]+weight[i]);
				}else {
					dp[i&1][j]=dp[(i-1)&1][j];
				}
			}
		}
		System.out.println(v-dp[n&1][v]);
	}
}
